﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using GPCSC.Model;
using GPCSC.DALFactory;
using GPCSC.IDAL;
namespace GPCSC.BLL
{
    /// <summary>
    /// ҵ���߼���CL_POST_S ��ժҪ˵����
    /// </summary>
    public class CL_POST_S
    {
        private readonly ICL_POST_S dal = DataAccess.CreateCL_POST_S();
        public CL_POST_S()
        { }
        #region  ��Ա����
        /// <summary>
        /// �Ƿ���ڸü�¼
        /// </summary>
        public bool Exists(Guid CL_POST_SOID)
        {
            return dal.Exists(CL_POST_SOID);
        }

        /// <summary>
        /// ����һ������
        /// </summary>
        public void Add(GPCSC.Model.CL_POST_S model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// ����һ������
        /// </summary>
        public void Update(GPCSC.Model.CL_POST_S model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// ɾ��һ������
        /// </summary>
        public void Delete(Guid CL_POST_SOID)
        {

            dal.Delete(CL_POST_SOID);
        }

        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public GPCSC.Model.CL_POST_S GetModel(Guid CL_POST_SOID)
        {

            return dal.GetModel(CL_POST_SOID);
        }

        /// <summary>
        /// �õ�һ������ʵ�壬�ӻ����С�
        /// </summary>
        public GPCSC.Model.CL_POST_S GetModelByCache(Guid CL_POST_SOID)
        {

            string CacheKey = "CL_POST_SModel-" + CL_POST_SOID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(CL_POST_SOID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (GPCSC.Model.CL_POST_S)objModel;
        }

        /// <summary>
        /// ��������б�
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// ��������б�
        /// </summary>
        public List<GPCSC.Model.CL_POST_S> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<GPCSC.Model.CL_POST_S> modelList = new List<GPCSC.Model.CL_POST_S>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                GPCSC.Model.CL_POST_S model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new GPCSC.Model.CL_POST_S();
                    if (ds.Tables[0].Rows[n]["CL_POST_SOID"].ToString() != "")
                    {
                        model.CL_POST_SOID = new Guid(ds.Tables[0].Rows[n]["CL_POST_SOID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["PD_CompanyInfoSOID_PK"].ToString() != "")
                    {
                        model.PD_CompanyInfoSOID_PK = new Guid(ds.Tables[0].Rows[n]["PD_CompanyInfoSOID_PK"].ToString());
                    }
                    model.PD_CompanyName = ds.Tables[0].Rows[n]["PD_CompanyName"].ToString();
                    model.POSTNAME = ds.Tables[0].Rows[n]["POSTNAME"].ToString();
                    model.REMARK = ds.Tables[0].Rows[n]["REMARK"].ToString();
                    if (ds.Tables[0].Rows[n]["status"].ToString() != "")
                    {
                        model.status = int.Parse(ds.Tables[0].Rows[n]["status"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Depth"].ToString() != "")
                    {
                        model.Depth = int.Parse(ds.Tables[0].Rows[n]["Depth"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["CL_PARPOSTID_PK"].ToString() != "")
                    {
                        model.CL_PARPOSTID_PK = new Guid(ds.Tables[0].Rows[n]["CL_PARPOSTID_PK"].ToString());
                    }
                    model.PARPOSTNAME = ds.Tables[0].Rows[n]["PARPOSTNAME"].ToString();
                    model.Tab = ds.Tables[0].Rows[n]["Tab"].ToString();
                    if (ds.Tables[0].Rows[n]["Number"].ToString() != "")
                    {
                        model.Number = int.Parse(ds.Tables[0].Rows[n]["Number"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// ��������б�
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// ��������б�
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  ��Ա����
    }
}

